package zhku.zjfw.antiFack.HttpTask;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Message;

public class LoadImageAsyncTask extends AsyncTask<String, Void, Bitmap> {
	
	PreOrAfterAsyncTask preOrAfterAsyncTask;
	public LoadImageAsyncTask(PreOrAfterAsyncTask preOrAfterAsyncTask){
		this.preOrAfterAsyncTask = preOrAfterAsyncTask;
	};
	
	@Override
	protected void onPreExecute() {
		preOrAfterAsyncTask.doPreAsncTask();
		super.onPreExecute();
	}
	
	@Override
	protected void onPostExecute(Bitmap result) {
		preOrAfterAsyncTask.doAfterAsyncTask(result);
		super.onPostExecute(result);
	}

	@Override
	protected Bitmap doInBackground(String... params) {
		Bitmap bitmap = null;
		URL connurl;
		try {
			connurl = new URL(params[0]);
			HttpURLConnection conn = (HttpURLConnection) connurl.openConnection();
			conn.setConnectTimeout(5000);
			conn.setReadTimeout(10000);
			bitmap = BitmapFactory.decodeStream((InputStream) conn.getContent());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return bitmap;
    }

}
